"use strict";TABS.adjustments={},TABS.adjustments.initialize=function(n){function e(){MSP.send_message(MSP_codes.MSP_ADJUSTMENT_RANGES,!1,!1,a)}function a(){MSP.send_message(MSP_codes.MSP_BOXIDS,!1,!1,t)}function t(){MSP.send_message(MSP_codes.MSP_RC,!1,!1,s)}function s(){$("#content").load("./tabs/adjustments.html",i)}function d(n,e,a){var t=$("#tab-adjustments-templates .adjustments .adjustment"),s=t.clone();$(s).attr("id","adjustment-"+n),$(s).data("index",n);var d=$(s).find(".adjustmentSlot .slot");d.val(e.slotIndex);var d=$(s).find(".channelInfo .channel"),i=$(d).find("option");i.remove();for(var l=0;l<a;l++){var r=i.clone();r.text("AUX "+(l+1)),r.val(l),d.append(r)}d.val(e.auxChannelIndex);var d=$(s).find(".functionSelection .function");d.val(e.adjustmentFunction);var d=$(s).find(".functionSwitchChannel .channel"),i=$(d).find("option");i.remove();for(var l=0;l<a;l++){var r=i.clone();r.text("AUX "+(l+1)),r.val(l),d.append(r)}d.val(e.auxSwitchChannelIndex);var c={min:[900],max:[2100]},o=[1300,1700],u=o;void 0!=e.range&&(u=[e.range.start,e.range.end]);var f=$(s).find(".range");$(f).find(".channel-slider").noUiSlider({start:u,behaviour:"snap-drag",step:25,connect:!0,range:c,format:wNumb({decimals:0})});$(s).find(".channel-slider").Link("lower").to($(s).find(".lowerLimitValue")),$(s).find(".channel-slider").Link("upper").to($(s).find(".upperLimitValue")),$(f).find(".pips-channel-range").noUiSlider_pips({mode:"values",values:[900,1e3,1200,1400,1500,1600,1800,2e3,2100],density:4,stepped:!0});var S=$(s).find(".enable");$(S).data("adjustmentElement",s),$(S).change(function(){var n=$(this).data("adjustmentElement");if($(this).prop("checked")){$(n).find(":input").prop("disabled",!1),$(n).find(".channel-slider").removeAttr("disabled");var e=$(n).find(".range .channel-slider"),a=$(e).val();if(a[0]==a[1]){var t=[1300,1700];$(e).val(t)}}else $(n).find(":input").prop("disabled",!0),$(n).find(".channel-slider").attr("disabled","disabled");$(this).prop("disabled",!1)});var h=e.range.start!=e.range.end;return $(S).prop("checked",h).change(),s}function i(){function e(n,e){e<900?e=900:e>2100&&(e=2100);var a=(e-900)/1200*100;$(".adjustments .adjustment").each(function(){var e=$(this).find(".channel").val();e==n&&$(this).find(".range .marker").css("left",a+"%")})}function a(){MSP.send_message(MSP_codes.MSP_RC,!1,!1,t)}function t(){for(var n=RC.active_channels-4,a=0;a<n;a++)e(a,RC.channels[a+4])}for(var s=RC.active_channels-4,i=$(".tab-adjustments .adjustments tbody"),l=0;l<ADJUSTMENT_RANGES.length;l++){var r=d(l,ADJUSTMENT_RANGES[l],s);i.append(r)}translateAll(),$("a.save").click(function(){function n(){MSP.send_message(MSP_codes.MSP_EEPROM_WRITE,!1,!1,function(){GUI.log(getMessage("adjustmentsEepromSaved"))})}var e=ADJUSTMENT_RANGES.length;ADJUSTMENT_RANGES=[];var a={slotIndex:0,auxChannelIndex:0,range:{start:900,end:900},adjustmentFunction:0,auxSwitchChannelIndex:0};$(".tab-adjustments .adjustments .adjustment").each(function(){var n=$(this);if($(n).find(".enable").prop("checked")){var e=$(this).find(".range .channel-slider").val(),t={slotIndex:parseInt($(this).find(".adjustmentSlot .slot").val()),auxChannelIndex:parseInt($(this).find(".channelInfo .channel").val()),range:{start:e[0],end:e[1]},adjustmentFunction:parseInt($(this).find(".functionSelection .function").val()),auxSwitchChannelIndex:parseInt($(this).find(".functionSwitchChannel .channel").val())};ADJUSTMENT_RANGES.push(t)}else ADJUSTMENT_RANGES.push(a)});for(var t=ADJUSTMENT_RANGES.length;t<e;t++)ADJUSTMENT_RANGES.push(a);MSP.sendAdjustmentRanges(n)}),t(),GUI.interval_add("aux_data_pull",a,50),GUI.interval_add("status_pull",function(){MSP.send_message(MSP_codes.MSP_STATUS)},250,!0),n&&n()}GUI.active_tab_ref=this,GUI.active_tab="adjustments",googleAnalytics.sendAppView("Adjustments"),MSP.send_message(MSP_codes.MSP_BOXNAMES,!1,!1,e)},TABS.adjustments.cleanup=function(n){n&&n()};